<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名" prop="MemberName">
        <el-input v-model="form.MemberName"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="PassWord">
        <el-input v-model="form.PassWord"></el-input>
      </el-form-item>
     
      <el-form-item label="职位" prop="UserTypeID">
        <el-select
          v-model="form.UserTypeID"
          placeholder="请输入您的职位"
          clearable
          prop="MemberName"
        >
          <el-option
            v-for="item in usertype"
            :key="item.UserTypeID"
            :label="item.UserTypeName"
            :value="item.UserTypeID"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户人" prop="UserInfoName">
        <el-input v-model="form.UserInfoName"></el-input>
      </el-form-item>
      <el-form-item label="用户人手机号" prop="UserInfoPhone">
        <el-input v-model="form.UserInfoPhone"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="UserInfoSex">
        <el-radio-group v-model="form.UserInfoSex">
          <el-radio label="true">男</el-radio>
          <el-radio label="false">女</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="生日" prop="UserInfoDate">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.UserInfoDate"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-upload
        class="avatar-uploader"
        action="https://localhost:5001/api/Member/Mages"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :name="this.form.UserImg"
      >
        <img v-if="form.UserImg" :src="form.UserImg" class="avatar" />
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">修改</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import axios from "@/util/axios.js";
export default {
  data() {
    return {
      form: {
        MemberName: "",
        PassWord: "",
        UserTypeID: "",
       MemberID:"",
        UserInfoName: "",
        UserInfoPhone: "",
        UserInfoSex: "",
        UserInfoDate: "",
        UserImg: "",
        MemberRoleId:""
      },
      usertype: [],
    };
  },

  methods: {
    getusertype() {
      axios.get("api/UserTypes/GetUserTypes").then((res) => {
        this.usertype = res.data;
      });
    },
    gettable() {
      let id = this.$route.query.id;
      axios.get("api/Member/GetMembersById?memberid=" + id).then((res) => {
        this.form=res.data.list[0];
       
      });
    },
    onSubmit() {
      axios.put("api/Member/Update", this.form).then((res) => {
        if (res.data.Code == 2) {
          this.$message("用户名已被占用");
        } else if (res.data.Code == 3) {
          this.$message("一个手机号只能注册一个账号");
        } else {
            this.$message("修改成功");
        this.$router.push({name:"UserList"});
        }
      });
    },
    handleAvatarSuccess(res) {
      this.form.UserImg = res.filepath;
    },
  },
  created() {
    this.getusertype();
    this.gettable();
  },
};
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>